package com.jh.paymentchannel.pojo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jh.paymentchannel.payment.OrderType;
import com.jh.paymentchannel.payment.TradeStatus;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

/**
 * 快银用户下单表
 * @author lichengying
 */
@Entity
@Table(name="t_taiwan_card_order")
public class TaiwanCardOrder implements Serializable {

    private static final long serialVersionUID = -5654046976981813083L;

    @Id
    @Column(name="id")
    private long id;

    /** 订单号 */
    @Column(name = "order_no")
    private String orderNo;

    /** 用户id */
    @Column(name = "user_id")
    private Long userId;

    /** 商户id **/
    @Column(name="merchant_id")
    private String merchantId;

    /** 商铺简称 **/
    @Column(name="merchant_name")
    private String merchantName;

    /**
     * 商铺全称
     */
    @Column(name="shop_name")
    private String shopName;

    /**
     * 用户名称
     */
    @Column(name="user_name")
    private String userName;

    /**消费金额*/
    @Column(name="total_amount")
    private BigDecimal totalAmount;

    /** 商户分润 */
    @Column(name = "merchant_fee")
    private BigDecimal merchantFee;

    /** 代理商分润 */
    @Column(name = "agent_fee")
    private BigDecimal agentFee;

    /**
     * 平台分润
     */
    @Column(name = "platform_fee")
    private BigDecimal platformFee;

    /** 商品描述 */
    @Column(name="body")
    private String body;

    /** 商品详情 */
    @Column(name="detail")
    private String detail;

    /** 订单类型 */
    @Enumerated(EnumType.STRING)
    @Column(name="order_type")
    private OrderType orderType;

    /** 交易状态 */
    @Enumerated(EnumType.STRING)
    @Column(name="trade_status")
    private TradeStatus tradeStatus;

    @Column(name="update_time")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    @Column(name="create_time")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /** 贴牌商 */
    @Column(name = "brand_id")
    private int brandId;

    /** 代理商id */
    @Column(name = "pre_user_id")
    private int preUserId;

    /** 清算状态 */
    @Column(name = "sel_status")
    private String selStatus;

    @Transient
    private String orderTypeCN;
    @Transient
    private String tradeStatusCN;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getMerchantId() {
        return merchantId;
    }

    public void setMerchantId(String merchantId) {
        this.merchantId = merchantId;
    }

    public String getMerchantName() {
        return merchantName;
    }

    public void setMerchantName(String merchantName) {
        this.merchantName = merchantName;
    }

    public String getShopName() {
        return shopName;
    }

    public void setShopName(String shopName) {
        this.shopName = shopName;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public BigDecimal getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public BigDecimal getMerchantFee() {
        return merchantFee;
    }

    public void setMerchantFee(BigDecimal merchantFee) {
        this.merchantFee = merchantFee;
    }

    public BigDecimal getAgentFee() {
        return agentFee;
    }

    public void setAgentFee(BigDecimal agentFee) {
        this.agentFee = agentFee;
    }

    public BigDecimal getPlatformFee() {
        return platformFee;
    }

    public void setPlatformFee(BigDecimal platformFee) {
        this.platformFee = platformFee;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public OrderType getOrderType() {
        return orderType;
    }

    public void setOrderType(OrderType orderType) {
        this.orderType = orderType;
    }

    public TradeStatus getTradeStatus() {
        return tradeStatus;
    }

    public void setTradeStatus(TradeStatus tradeStatus) {
        this.tradeStatus = tradeStatus;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public int getBrandId() {
        return brandId;
    }

    public void setBrandId(int brandId) {
        this.brandId = brandId;
    }

    public int getPreUserId() {
        return preUserId;
    }

    public void setPreUserId(int preUserId) {
        this.preUserId = preUserId;
    }

    public String getSelStatus() {
        return selStatus;
    }

    public void setSelStatus(String selStatus) {
        this.selStatus = selStatus;
    }

    public String getOrderTypeCN() {
        return orderTypeCN;
    }

    public void setOrderTypeCN(String orderTypeCN) {
        this.orderTypeCN = orderTypeCN;
    }

    public String getTradeStatusCN() {
        return tradeStatusCN;
    }

    public void setTradeStatusCN(String tradeStatusCN) {
        this.tradeStatusCN = tradeStatusCN;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof TaiwanCardOrder)) return false;
        TaiwanCardOrder order = (TaiwanCardOrder) o;
        return getId() == order.getId() &&
                getBrandId() == order.getBrandId() &&
                getPreUserId() == order.getPreUserId() &&
                Objects.equals(getOrderNo(), order.getOrderNo()) &&
                Objects.equals(getUserId(), order.getUserId()) &&
                Objects.equals(getMerchantId(), order.getMerchantId()) &&
                Objects.equals(getMerchantName(), order.getMerchantName()) &&
                Objects.equals(getShopName(), order.getShopName()) &&
                Objects.equals(getUserName(), order.getUserName()) &&
                Objects.equals(getTotalAmount(), order.getTotalAmount()) &&
                Objects.equals(getMerchantFee(), order.getMerchantFee()) &&
                Objects.equals(getAgentFee(), order.getAgentFee()) &&
                Objects.equals(getPlatformFee(), order.getPlatformFee()) &&
                Objects.equals(getBody(), order.getBody()) &&
                Objects.equals(getDetail(), order.getDetail()) &&
                getOrderType() == order.getOrderType() &&
                getTradeStatus() == order.getTradeStatus() &&
                Objects.equals(getUpdateTime(), order.getUpdateTime()) &&
                Objects.equals(getCreateTime(), order.getCreateTime()) &&
                Objects.equals(getSelStatus(), order.getSelStatus()) &&
                Objects.equals(getOrderTypeCN(), order.getOrderTypeCN()) &&
                Objects.equals(getTradeStatusCN(), order.getTradeStatusCN());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getId(), getOrderNo(), getUserId(), getMerchantId(), getMerchantName(), getShopName(), getUserName(), getTotalAmount(), getMerchantFee(), getAgentFee(), getPlatformFee(), getBody(), getDetail(), getOrderType(), getTradeStatus(), getUpdateTime(), getCreateTime(), getBrandId(), getPreUserId(), getSelStatus(), getOrderTypeCN(), getTradeStatusCN());
    }

    @Override
    public String toString() {
        return "TaiwanCardOrder{" +
                "id=" + id +
                ", orderNo='" + orderNo + '\'' +
                ", userId=" + userId +
                ", merchantId='" + merchantId + '\'' +
                ", merchantName='" + merchantName + '\'' +
                ", shopName='" + shopName + '\'' +
                ", userName='" + userName + '\'' +
                ", totalAmount=" + totalAmount +
                ", merchantFee=" + merchantFee +
                ", agentFee=" + agentFee +
                ", platformFee=" + platformFee +
                ", body='" + body + '\'' +
                ", detail='" + detail + '\'' +
                ", orderType=" + orderType +
                ", tradeStatus=" + tradeStatus +
                ", updateTime=" + updateTime +
                ", createTime=" + createTime +
                ", brandId=" + brandId +
                ", preUserId=" + preUserId +
                ", selStatus='" + selStatus + '\'' +
                ", orderTypeCN='" + orderTypeCN + '\'' +
                ", tradeStatusCN='" + tradeStatusCN + '\'' +
                '}';
    }

    public PaymentView transform() {
        PaymentView order = new PaymentView();
        order.setMerchantId(getMerchantId());
        order.setUserId(getUserId());
        order.setMerchantName(getMerchantName());
        order.setOrderNo(getOrderNo());
        order.setBody(getBody());
        order.setShopName(getShopName());
        order.setUserName(getUserName());
        order.setDetail(getDetail());
        if (getOrderType() != null) {
            order.setOrderType(getOrderType().getDesc());
        }
        if (getTradeStatus() != null) {
            order.setTradeStatus(getTradeStatus().getDesc());
        }

        order.setTotalAmount(getTotalAmount());
        order.setAgentFee(getAgentFee());
        order.setCreateTime(getCreateTime());
        order.setSelStatus(getSelStatus());
        return order;
    }
}
